<?php

################# Einstell Variablen ############################################################################
$onlinelistsize=8;         # Hoehe des Selectfeld der Onlinuser
$showbuddy=1;                          # Buddylink (Messenger) anzeigen
$checkpmtime=200000;        # 200000 Intervall zum private Nachrichten abfragen, 0 wenn nicht abgefragt werden soll
# User, die nicht angezeigt werden sollen
# Namen mit Komma trennen!
$excludedusers ="";
##################################################################################################################
$imagedir="images/messenger";
$pm_module_name = "Messenger";
##################################################################################################################
$thisfile=basename(__file__);

if (eregi("block-User_Info.php",$_SERVER['PHP_SELF'])) {
    Header("Location: index.php");
    die();
}
?>
<script language="javascript">
<!--

        function prvmsgto(IM) {
                window.open('modules.php?name=Messenger&file=buddy&op=compose&to='+IM, '86959ccb04a43983401372d0404907b6','left=370,top=150,width=360,height=200,toolbar=no,location=no,menubar=no,scrollbars=yes,resizeable=yes,status=no');
                }
        // -->
</script>
<?PHP
global $admin, $user, $prefix, $user_prefix, $dbi, $cookie, $currentlang, $blockfiletitle, $anonymous;
global $bgcolor1, $bgcolor2, $bgcolor3, $txtcolor1, $txtcolor2, $uname, $nukeurl, $db;

if(file_exists("language/maaXoN-$currentlang.php")) {
        include_once("language/maaXoN-$currentlang.php");
        }
else {
        include_once("language/maaXoN-turkish.php");
        }
# Variablen initialisieren
if($currentlang=="german"){        # Bilder fuer Buttons definieren (noch keine Bilder vorhanden!!)
        $pmimagepath="modules/$pm_module_name/images/buttons/german";
        }
else{
        $pmimagepath="modules/$pm_module_name/images/buttons/english";
        }

# Variablen initialisieren
$ip = getenv("REMOTE_ADDR");
if (is_user($user)){
        cookiedecode($user);
        $uname = $cookie[1];
        $user_id = $cookie[0];
        $guest=0;
        }
else {
        $uname = "$ip";
        $guest=1;
        $showscrollist=0;
        }

$past = time()-900; $ctime = time();
$countpm=0; $countpmunread=0;
$userlist=""; $totalmembers=0;
$gbactiv=0; $gbnewentries=0;
$whoonlinelist = ""; $whoonlineselect = "";
$member_online_num = 1; $guest_online_num=0;
$pmactiv=0;
$isseradmin=is_admin($admin);
# SQL-bedingung fuer excluded Users erstellen
$exusers = explode (",", $excludedusers);
if(!$isseradmin){
        while (list($key, $val) = each($exusers)) {
                $xexusers[]="\"".trim($val)."\"";
                }
        }
$xexusers[]="\"$anonymous\"";
$excludedusers=implode($xexusers,",");

# alte User aus session loeschen
sql_query("DELETE FROM ".$prefix."_session WHERE time < $past",$dbi);

# ermitteln ob aktueller User bereits in Session eingetragen
$result = sql_query("SELECT time FROM ".$prefix."_session WHERE uname='$uname'",$dbi);
if ($row = sql_fetch_row($result,$dbi)) { # falls ja, Daten aktualisieren
        sql_query("UPDATE ".$prefix."_session SET uname='$uname', time='$ctime', host_addr='$ip', guest='$guest' WHERE uname='$uname'",$dbi);
        }
else { # falls nein, User in Session eintragen
        sql_query("INSERT INTO ".$prefix."_session (uname, time, host_addr, guest) VALUES ('$uname', '$ctime', '$ip', '$guest')",$dbi);
        }
mysql_free_result($result);
# Anzahl aller User ermitteln
$qry="select COUNT(user_id) from ".$user_prefix."_users";
list($totalmembers) = sql_fetch_row(sql_query($qry,$dbi),$dbi);

# neusten User ermitteln
$qry="select username from ".$user_prefix."_users where user_id<>1 and username<>'".$anonymous."' order by user_id DESC limit 0,1;";
$result = sql_query($qry,$dbi);        # neusten User ermitteln
list($lastuser) = sql_fetch_row($result,$dbi);

# Alle User und Gaeste ermitteln, evtl auflisten
$qry="SELECT DISTINCT guest, uname FROM ".$prefix."_session where (guest=0 or guest=1) and uname not in($excludedusers) order by uname;";
$result2 = sql_query($qry,$dbi);
while (list($sesionguest, $uname2) = sql_fetch_row($result2,$dbi)) {
  if ($sesionguest==0) {        # wenn angemeldeter User
                if(isset($uname))
                        if(strtolower($uname2)==strtolower($uname)) {$sel="selected";} else{$sel="";}
                else
                        if(strtolower($uname2)==strtolower($username)) {$sel="selected";} else{$sel="";}
                $uname3 = substr("$uname2", 0, 20);
                $whoonlineselect.="<option value=\"$uname2\" $sel>$uname3</OPTION>\n";
                $member_online_num++;        # Anzahl User hochzaehlen
          }
        else{
                $guest_online_num++;        # Anzahl Gaeste hochzaehlen
                }
        }
$member_online_num=$member_online_num-1;        # Wieder einen User abziehen (war bei init 1)
mysql_free_result($result2);
# Private Nachrichten
if ($guest == 0) { # Wenn aktueller User registriert ist (kein Gast)
        $pmactiv=is_active("$pm_module_name"); # feststellen ob pm-modul aktiv ist
        if ($pmactiv){        # falls pm-modul aktiv ist
                $qry="SELECT read_msg, Count(msg_id) FROM ".$prefix."_priv_msgs WHERE to_userid='$user_id' group by read_msg;";
                $result = sql_query($qry,$dbi);
                while (list($read_msg, $nums) = sql_fetch_row($result,$dbi)) {
                  if ($read_msg==0) {        # wenn angemeldeter User
                                $countpmunread=$nums;        # Anzahl ungelesene ermitteln
                          }
                        else{
                                $countpm=$nums;        #++;        # Anzahl aller pm's ermitteln
                                }
                        }
                }
        else{
                $checkpmtime=0; # private Nachrichten nicht abfragen!
                }
        }

$Today = getdate();
//Formatting Current Date
$month = $Today['month'];
$mday = $Today['mday'];
$year = $Today['year'];
//Formatting Previous Date
$pmonth = $Today['mon'];
$pmday = $Today['mday'];
$pmday = $mday-1;
$pyear = $Today['year'];
$test = mktime (0,0,0,$pmonth,$pmday,$pyear,1);
//Creating SQL parameter
$curDate2 = "%".$month[0].$month[1].$month[2]."%".$mday."%".$year."%";
$preday = strftime ("%d",$test);
$premonth = strftime ("%B",$test);
$preyear = strftime ("%Y",$test);
$curDateP = "%".$premonth[0].$premonth[1].$premonth[2]."%".$preday."%".$preyear."%";
# Heute neu angemeldete User ermitteln
$qry = "SELECT COUNT(user_id) from ".$user_prefix."_users WHERE user_regdate LIKE '$curDate2' and  username not in($excludedusers);";
list($userCount) = sql_fetch_row(sql_query($qry,$dbi),$dbi);
# Gestern neu angemeldete User ermitteln
$qry = "SELECT COUNT(user_id) from ".$user_prefix."_users WHERE user_regdate LIKE '$curDateP' and username not in($excludedusers);";
list($userCount2) = sql_fetch_row(sql_query($qry,$dbi),$dbi);
# Ausgabe ...................................
$content = "\n<!-- $thisfile output start -->\n<div class=\"content\" align=\"center\">\n"
."<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"border: 0px; margin-bottom: 5px;\">\n"
."\n<tr>\n<td>"._BWOTOTALMEMBERS."</td>\n<td align=\"right\">\n<b>$totalmembers</b></td>\n</tr>\n"
//."\n<tr>\n<td>"._BWOTODAYMEMBERS."</td>\n<td align=\"right\">\n<b>$userCount</b></td>\n</tr>\n"
//."\n<tr>\n<td>"._BWOYESTERDAYMEMBERS."</td>\n<td align=\"right\">\n<b>$userCount2</b></td>\n</tr>\n"
."\n<tr>\n<td>"._BWOMEMBERS1."</td>\n<td align=\"right\">\n<b>$member_online_num</b></td>\n</tr>\n"
."\n<tr>\n<td>"._BWOGUESTES."</td>\n<td align=\"right\">\n<b>$guest_online_num</b></td>\n</tr>\n"
."</table>\n";
if ($guest == 0 || $isseradmin) {        # Wenn angemeldeter User oder Admin
        # Onlineliste anzeigen wenn User online sind
        if($member_online_num>0){
                if($onlinelistsize>=$member_online_num) {$onlinelistsize=$member_online_num+1;}
                $content .= "<div style=\"border: 0px; margin-bottom: 5px;\">"._BWOLATEMEMBER."<br>\n<A HREF=\"modules.php?name=Your_Account&op=userinfo&username=$lastuser\">$lastuser</a></div>\n";
                if($guest){
                        $script = "";
                        }
                else{
                        $script = " onDblClick=\"whob_clickit()\"";
                        $content .= "<script language=\"JavaScript\">
<!--
function whob_clickit(){
        var y=document.onlineuserinfo.username.selectedIndex;
        var x=document.onlineuserinfo.username.options[y].value;
        window.open('modules.php?name=$pm_module_name&file=buddy&op=compose&to='+x, '".md5(time())."','left=370,top=150,width=360,height=200,toolbar=no,location=no,menubar=no,scrollbars=yes,resizeable=yes,status=no');
        return false;
        }
//-->
</script>";
                }
        #background-color: $bgcolor1; font-size: 9px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: $txtcolor1; width: 90%; border: 0px $bgcolor1;

        $content .= "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"border: 0px; margin-bottom: 5px;\">\n";
        $content .= "\n<tr>\n<td colspan=\"2\" align=\"center\">\n";
        $content .= "<img src=\"$imagedir/group-1.gif\" width=\"16\" height=\"16\" border=\"0\" Alt=\"Şu an bağlı\" align=\"absmiddle\">\n<b><u>"._BWOONLINELIST."</u></b>\n<br>\n";
        $content .= "</td>\n</tr>\n";
        $content .= "\n<tr>\n<td colspan=\"2\" align=\"center\">";        # select-options verwenden
        $content .= "<form action=\"modules.php?test\" name=\"onlineuserinfo\" method=\"get\" style=\"border: 0px; margin-bottom: 5px; margin-top: 0px;\">";
        $content .= "<input type=\"hidden\" name=\"name\" value=\"Your_Account\">";
        $content .= "<input type=\"hidden\" name=\"op\" value=\"userinfo\">";
        $content .= "<select name=\"username\" size=\"$onlinelistsize\" style=\" background-color: $bgcolor1; font-size: 9px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: $txtcolor1; width: 90%; cursor : hand;        border: 1px solid $bgcolor2; text-decoration: none; padding-left: 1px; padding-top: 1px; padding-bottom: 1px;\" $script>$whoonlineselect</select>";
        $content .= "<br>\n<input type=\"image\" src=\"$imagedir/info.gif\" alt=\""._BWOUSERINFO."\" border=\"0\">";
        $content .= "</form>\n";
        $content .= "<hr></td>\n</tr>\n";
        $content .= "</table>\n";
        }
        # private messages
        if ($pmactiv){
                # pm Liste
                $content .= "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"border: 0px; margin-bottom: 5px;\">\n";
                if ($countpm){
                        $content .= "\n<tr>\n<td colspan=\"3\" align=\"center\"><a href=\"modules.php?name=Messenger\">"._BWOPMSG."</a></td>\n</tr>\n";
                      //  $content .= "\n<tr>\n<td align=\"center\"><a href=\"modules.php?name=Messenger\"><img src=\"$imagedir/pmessage.gif\" width=\"19\" height=\"19\" border=\"0\" Alt=\""._BWOPMSG."\"></a></td>\n";
                        $content .= "<td valign=\"top\">"._BWOPMSGALL.":<br>\n"._BWOPMSGUNREAD.":</td>\n";
                        $content .= "<td valign=\"top\" align=\"right\"><b>$countpm</b><br>\n";
                        if($countpmunread){
                                $content .= "<marquee behavior=\"alternate\" direction=\"left\" hspace=\"0\" vspace=\"0\" loop=\"\" height=\"5\" align=\"right\"><b><blink>$countpmunread</blink></b></marquee>";
                                }
                        else{
                                $content .= "<b>$countpmunread</b>";
                                }
                        $content .= "</td>\n</tr>\n";
                        }
                else{
                   //     $content .= "<tr><td><a href=\"modules.php?name=Messenger\"><img src=\"$imagedir/pmessage.gif\" width=\"19\" height=\"19\" border=\"0\" Alt=\""._BWOPMSG."\" hspace=\"0\"></a></td><td><a href=\"modules.php?name=Messenger\">"._BWOPMSG."</a></td></tr>\n";
                        }
                $content .= "</table>\n";
        # Buddy
                if ($showbuddy){
                        $windowname=md5($sitename);
                        $content .= "
                        <a href=\"#\" onClick=\"window.open('modules.php?name=Messenger&file=buddy','$windowname','left=180, top=150, width=200,height=350,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,copyhistory=0'); return false;\">
                        <img src=\"$imagedir/buddy.gif\" width=\"100\" height=\"25\" border=\"0\" Alt=\""._BWOBUDDIE."\"></a><br>
                        <br><a href=\"Javascript:void(0);\" onClick=\"window.open('http://www.icq.com/icq2go/web.html','$windowname','left=180, top=150, width=158,height=446,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0');\"><img src=\"images/messenger/webicq.gif\" border=\"0\" Alt=\"WEB ICQ\";\"></a>\n";
             $content.= "<hr><b>Online Yöneticiler</b>";
               function adminonlinea($admin)
    {
    global $admin, $prefix, $db;
    if(!is_array($admin))
	    {
	    $admin = base64_decode($admin);
        $admin = explode(":", $admin);
        $uname = "$admin[0]";
	    $pwd = "$admin[1]";
	    }
    else
        {
        $uname = "$admin[0]";
	    $pwd = "$admin[1]";
	    }
    $past = time()-600;
    $sql = "DELETE FROM ".$prefix."_adminsession WHERE time < $past";
    $db->sql_query($sql);
    $sql = "SELECT * FROM ".$prefix."_adminsession WHERE uname='$uname'";
    $result = $db->sql_query($sql);
    if(is_admin($admin))
        {
	    $ctime = time();
        if ($row = $db->sql_fetchrow($result))
            {
	        $sql = "UPDATE ".$prefix."_adminsession SET uname='$uname', time='$ctime' WHERE uname='$uname'";
	        $db->sql_query($sql);
            }
        else
	        {
	        $sql = "INSERT INTO ".$prefix."_adminsession (uname, time) VALUES ('$uname', '$ctime')";
	        $db->sql_query($sql);
            }
        }
    }
adminonlinea($admin);
$sql = "SELECT uname FROM ".$prefix."_adminsession";
$result = $db->sql_query($sql);
if($db->sql_numrows($result) == "0")
    {
    $content .= "<br><i>Henüz online yönetici yok!</i>\n";
    }
else
    {
    while($row = $db->sql_fetchrow($result))
        {
        $content .= "<br><big><strong>&middot;</strong></big>\n ";
        if(is_active("Messenger") AND $db->sql_numrows($db->sql_query("SELECT * FROM ".$user_prefix."_users where username = '$row[uname]'")) == "1")
            {
            $content .= "<a href=\"javascript:prvmsgto('$row[uname]');\">\n<img src=\"images/pm.gif\" border=0 alt=\"Messenger Mesajı Yolla\"></a>";
            }
        if(is_active("Your_Account")) $content .= " <a href=\"modules.php?name=Your_Account&op=userinfo&username=$row[uname]\" alt=\"$row[uname] nickinin bilgilerini göster!\">$row[uname]</a>\n";
        else $content .= "$row[uname]\n";
        }
    }
                                               }
                }
        # Usergaestebuch

        }
else{        # Gast no user
mt_srand ((double)microtime()*1000000);
$maxran = 1000000;
$random_num = mt_rand(0, $maxran);

$content .= "<form action=\"modules.php?name=Your_Account\" method=\"post\">";
$content .= "<center><table border=0><tr><td><font class=\"content\"><b>"._NICKNAME."</b></td>";
$content .= "<td><input type=\"text\" name=\"username\" size=\"8\" maxlength=\"25\"></td></tR>";
$content .= "<tr><td><b>"._PASSWORD."</b></td>";
$content .= "<td><input type=\"password\" name=\"user_password\" size=\"8\" maxlength=\"20\"></td></tr>
</table>";
$content .= "<input type=\"hidden\" name=\"op\" value=\"login\">";
$content .= "<input type=\"submit\" value=\"   "._LOGIN."   \"></font></center></form><br><a href=modules.php?name=Your_Account&op=new_user>Üye Kayıt</a>";
        }

if(!$guest){
        $agent = strtoupper(getenv ("HTTP_USER_AGENT"));
        if (strstr($agent,"MSIE 5")
        || strstr($agent,"MSIE 6")
        || strstr($agent,"MSIE 7")
        || strstr($agent,"MSIE 8")
        || strstr($agent,"MSIE 4")
        || strstr($agent,"MSIE+4")
        || strstr($agent,"Explorer/4")
        || strstr($agent,"OPERA")
        || strstr($agent,"NETSCAPE6")
        || strstr($agent,"GECKO/2")
        || strstr($agent,"MOZILLA/5")
        ){
                $checkpmfile="modules.php?name=$pm_module_name&file=buddy&op=check&ref_intervall=$checkpmtime";
                $content.= "<div id=\"who_checkpm\"> </div>";
                $content.= "
                <script language=\"JavaScript1.2\">
                        var who_checkpm_anf='<iframe name=\"who_checkpm_1\" src=\"';
                        var who_checkpm_end='\" marginwidth=\"0\" marginheight=\"0\" width=\"0\" height=\"0\" scrolling=\"no\" frameborder=\"0\"></iframe>';
                        var who_dom = !!document.getElementById;
                        if(who_dom) document.getElementById('who_checkpm').innerHTML = who_checkpm_anf + '$checkpmfile' + who_checkpm_end;
                        else document.all['who_checkpm'].innerHTML = who_checkpm_anf + '$checkpmfile' + who_checkpm_end;
                </script>\n";
                }
        }
$content .= "</div>\n<!-- $thisfile output end -->\n";
# Blocktitel aus Sprachdatei auslesen
$blockfiletitle="Kimler Bağlı";
?>